<template>
  <!-- 今日优选 -->
  <div class="today">
    <div class="title">
      {{ data.name }}
    </div>
    <div class="goods-list">
      <el-row :gutter="20">
        <el-col
          v-for="(l, index) in list"
          :key="l.id"
          :span="12"
          @click.native="goDetail(l)"
        >
          <div v-if="index < 2">
            <div class="grid-content">
              <img
                :src="l.defaultAlbum"
                alt=""
              >
              <div class="goods-info">
                <div class="goods-name">
                  {{ l.pName }}
                </div>
                <div class="goods-button">
                  点击购买<img
                    src="../../assets/img/more.png"
                    alt=""
                  >
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col
          v-for="(l, index) in list"
          :key="l.id"
          :span="8"
          @click.native="goDetail(l)"
        >
          <div v-if="index >= 2">
            <div class="grid-content middle">
              <img
                :src="l.defaultAlbum"
                alt=""
              >

              <div class="goods-info">
                <div class="goods-name">
                  {{ l.pName }}
                </div>
                <div class="goods-button">
                  点击购买<img
                    src="../../assets/img/more.png"
                    alt=""
                  >
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="more">
      <img
        src="../../assets/img/logo2.png"
        alt=""
        @click="toList"
      >
    </div>
    <!-- <img src="../../assets/img/7@2x.png" alt="" class="adv" /> -->
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  props: {
    data: {
      type: Object,
      // 对象或数组默认值必须从一个工厂函数获取
      default: function () {
        return {};
      },
    },
  },
  data() {
    return {
      list: [],
    };
  },
  mounted() {
    let params = {
      queryCondition: {
        order: [
          {
            fieldname: "iOrder",
            direction: "asc",
          },
        ],
        pageindex: 1,
        pagesize: 5,
        where: [
          {
            fieldname: "tag_id",
            valuefrom: this.data.connect_id,
          },
        ],
      },
    };

    this.$api.home.getProductList(params).then((res) => {
      if (res.code == 200) {
        this.list = res.data.data;
        console.log("今日优选", this.list);
      }
    });
  },
  methods: {
    toList() {
      this.$router.push({
        path: "/today",
        query: {
          id: this.data.connect_id,
        },
      });
    },
    //跳转商品详情
    goDetail(item) {
      console.log('跳转商品详情', item)
      this.$router.push({
        path: "/fruit/detail",
        query: {
          id: item.pid,
          iShopId: item.iShopId
        },
      });
    },
  },
};
</script>

<style scoped lang="scss">
.today {
  padding: 0 10rem;
  margin-top: 2.19rem;
  display: flex;
  flex-direction: column;

  .title {
    width: 11.25rem;
    height: 3.44rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(234, 234, 234, 1);
  }

  .goods-list {
    margin-top: 1.88rem;
    width: 100%;

    .grid-content {
      border-radius: 4px;
      min-height: 22.06rem;
      background: #fff;
      margin-bottom: 1.31rem;
      display: flex;
      justify-content: space-around;
      align-items: center;

      > img {
        width: 15.75rem;
        height: 15.75rem;
        object-fit: contain;
        padding: 1rem;
      }

      .goods-info {
        display: flex;
        flex-direction: column;
        // padding: 0 1rem;
        .goods-name {
          font-size: 1.5rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(0, 0, 0, 1);
          line-height: 2.42rem;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          width: 22rem;
        }

        .goods-button {
          width: 7.5rem;
          height: 1.88rem;
          background: rgba(4, 0, 0, 1);
          font-size: 0.88rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(255, 255, 255, 1);
          display: flex;
          justify-content: center;
          align-items: center;
          margin-top: 1.69rem;
          cursor: pointer;

          img {
            margin-left: 0.5rem;
            width: 1.06rem;
            height: 1.25rem;
          }
        }
      }

      &.middle {
        > img {
          width: 12rem;
          height: 12rem;
          object-fit: contain;
          padding: 0 1rem;
        }

        .goods-info {
          display: flex;
          flex-direction: column;
          // padding: 0 1rem;
          // width: 100%;

          .goods-name {
            font-size: 1.5rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(0, 0, 0, 1);
            line-height: 2.42rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            width: 13rem;
          }

          .goods-button {
            width: 7.5rem;
            height: 2.19rem;
            background: rgba(4, 0, 0, 1);
            font-size: 0.88rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 1.69rem;
            cursor: pointer;

            img {
              margin-left: 0.5rem;
              width: 1.06rem;
              height: 1.25rem;
            }
          }
        }
      }
    }
  }

  .more {
    height: 2.5rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0 1.44rem;

    img {
      width: 7.38rem;
      cursor: pointer;
    }
  }

  .adv {
    width: 100%;
    margin-top: 3.69rem;
    object-fit: contain;
  }
}
</style>
